import {
  login,
  outLogin,
  getUserInfo,
  updatePwd,
  setUserSign,
} from '@/api/Login'

export default defineStore('useLogin', {
  state: () => ({}),
  getters: {},
  actions: {
    //登录
    async login(params) {
      let url = $globalRequestUrl({
        url: login,
      })

      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //退出登录
    async outLogin() {
      let url = $globalRequestUrl({
        url: outLogin,
      })

      try {
        const rep = await $globalRequest(url, {}, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },

    //获取用户详情
    async getUserInfo() {
      let url = $globalRequestUrl({
        url: getUserInfo,
      })

      try {
        const rep = await $globalRequest(url, {}, { method: 'GET' })
        return rep
      } catch (error) {
        return error
      }
    },
    //修改用户密码
    async updatePwd(params) {
      let url = $globalRequestUrl({
        url: updatePwd,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'PUT' })
        return rep
      } catch (error) {
        return error
      }
    },

    //设置签名
    async setUserSign(params) {
      let url = $globalRequestUrl({
        url: setUserSign,
      })
      try {
        const rep = await $globalRequest(url, params, { method: 'POST' })
        return rep
      } catch (error) {
        return error
      }
    },
  },
})
